package edu.mju.oss.controller;

import edu.mju.commonutils.ReturnCode;
import edu.mju.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author:wyp
 * @Date:2020/8/29 19:56
 */
@RestController
@RequestMapping("/eduoss/fileoss")
public class OssController {

    @Autowired
    private OssService ossService;

    /**
     *  上传头像方法
     * @param file 上传的文件
     * @return json数据
     */
    @PostMapping()
    public ReturnCode uploadOssFile(MultipartFile file){
        //获取上传文件 （MultipartFile）
        //返回上传的路径
        String url = ossService.uploadFile(file);

        Map<String,Object> map = new HashMap<>();
        map.put("url",url);
        return ReturnCode.success().data(map);
    }
}
